package com.sfzd5.exam.helplibrary.exam;

import java.util.ArrayList;
import java.util.List;

public class Page {
    public boolean hasExamInfo;

    public int pageId;
    public List<AreaDrawInfo> areaDrawInfoList;

    public float getFreeHeight(){
        float m = PageA4.contextHeightm() - (hasExamInfo ? PageA4.pageInfoHightm : 0);
        for(AreaDrawInfo a : areaDrawInfoList){
            if(a.startLine == 0)
                m -= PageA4.lineHightm;
            m -= PageA4.areaMarginm * 2;
            m -= PageA4.lineHightm * (a.endLine - a.startLine);
        }
        return m;
    }

    public Page(int pageId, boolean hasExamInfo){
        this.pageId = pageId;
        this.areaDrawInfoList = new ArrayList<>();
        this.hasExamInfo = hasExamInfo;
    }


    /**
     * 样便，可以获取本页的所有区域位置
     * @return
     */
    public List<Rectangle> getRectangles(){
        List<Rectangle> rectangleList = new ArrayList<>();
        float curTopm = PageA4.marginTopBottom;
        if(hasExamInfo) curTopm += PageA4.pageInfoHightm;
        for(AreaDrawInfo ac : areaDrawInfoList){
            if(ac.startLine==0){
                curTopm += PageA4.lineHightm;
            }
            Rectangle r = new Rectangle();
            r.x = PageA4.marginLeftRightm;
            r.y = curTopm;
            r.w = PageA4.contextWidthm();
            r.h = PageA4.lineHightm * (ac.endLine - ac.startLine) + PageA4.areaMarginm * 2;
            rectangleList.add(r);
        }
        return rectangleList;
    }
}
